using RockBus.DataContracts;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;

namespace RockBus.Hosting
{
    public class ReceivePortBehavior : IEndpointBehavior
    {
        public ReceivePortBehavior(PublisherReceivePortInfo publisherReceivePortInfo)
        {
            this.PublisherReceivePortInfo = publisherReceivePortInfo;
        }

        public PublisherReceivePortInfo PublisherReceivePortInfo { get; private set; }

        #region IEndpointBehavior Members

        public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters)
        {
            // Intentionally left blank
        }

        public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
        {
            // Intentionally left blank
        }

        public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
        {
            ReceivePortAddingMessageInspector inspector = new ReceivePortAddingMessageInspector(this.PublisherReceivePortInfo);
            endpointDispatcher.DispatchRuntime.MessageInspectors.Add(inspector);
        }

        public void Validate(ServiceEndpoint endpoint)
        {
            // Intentionally left blank
        }

        #endregion IEndpointBehavior Members
    }
}